\subsection{Definition of integral in two dimensions}
We can integrate over a bounded region \(D \subset \mathbb R^2\).
To do this, we can cover \(D\) with small, disjoint sets \(A_{ij}\) each with area \(\delta A_{ij}\).
Each of these sets \(A_{ij}\) are contained in a disc of radius \(\varepsilon > 0\).
Let \((x_i, y_j)\) be points contained in each \(A_{ij}\).
We now define
\[
	\int_D f(\vb x) \dd{A} = \lim_{\varepsilon \to 0} \sum_{i, j} f(x_i, y_j) \,\delta A_{ij}
\]
The integral exists if it is independent of the choice of partitions \(A_{ij}\) and the points \((x_i, y_j)\).
The obvious choice of partitioning \(D\) is to use rectangles where the area of each rectangle is \(\delta A_{ij} = \delta x_i \delta y_j\).
We can create horizontal `strips' of height \(\delta y\) which we can integrate over.
The possible \(x\) coordinates for this strip are \(x_y = \{ x \colon (x, y) \in D \}\).
We can take the limit as \(\delta x \to 0\), giving
\[
	\delta y \int_{x_y} f(x, y) \dd{x}
\]
Summing over each such strip, taking the limit as \(\delta y \to 0\), we have
\[
	\int_D f(x, y) \dd{A} = \int_Y \left( \int_{x_y} f(x, y) \dd{x} \right) \dd{y}
\]
where \(Y\) is the set of all possible \(y\) coordinates, i.e.\ \(Y = \{ y \colon \exists x, (x, y) \in D \}\).
We can equivalently sum over all vertical strips, and get
\[
	\int_D f(x, y) \dd{A} = \int_X \left( \int_{y_x} f(x, y) \dd{y} \right) \dd{x}
\]
More concisely, we can write the following (Fubini's Theorem):
\[
	\dd{A} = \dd{x} \dd{y} = \dd{y} \dd{x}
\]
Let us consider an example; let \(D\) be the triangle with vertices \((0, 0), (1, 0), (0, 1)\).
If \(f(x, y) = xy^2\), then by integrating over horizontal strips, we have
\begin{align*}
	\int_D f(x, y) \dd{A} & = \int_0^1 \left( \int_0^{1-y} xy^2 \dd{x} \right) \dd{y}  \\
	                      & = \int_0^1 \left[ \frac{1}{2}x^2y^2 \right]_0^{1-y} \dd{y} \\
	                      & = \int_0^1 \frac{1}{2}(1-y)^2y^2 \dd{y}                    \\
	                      & = \frac{1}{60}
\end{align*}
Instead, integrating over vertical strips, we have
\begin{align*}
	\int_D f(x, y) \dd{A} & = \int_0^1 \left( \int_0^{1-x} xy^2 \dd{y} \right) \dd{x} \\
	                      & = \int_0^1 \left[ \frac{1}{3} xy^3 \right]_0^{1-x} \dd{x} \\
	                      & = \int_0^1 \frac{1}{3} x(1-x)^3 \dd{x}                    \\
	                      & = \frac{1}{60}
\end{align*}
Note that if \(f(x, y) = g(x) \cdot h(y)\), and \(D\) is a rectangle \(\{ (x, y) \colon a \leq x \leq b, c \leq y \leq d \}\), then
\[
	\int_A f(x, y) \dd{A} = \left( \int_a^b g(x) \dd{x} \right)\left( \int_c^d h(y) \dd{y} \right)
\]

\subsection{Change of variables}
It can be useful to introduce a change of variables in order to compute the one-dimensional integral.
For example, if \(x\) is represented as a function of \(u\),
\[
	\int_a^b f(x) \dd{x} = \int_{x^{-1}(a)}^{x^{-1}(b)} f(x(u)) \frac{\dd{x}}{\dd{u}}\dd{u}
\]
Note that if \(\frac{\dd{x}}{\dd{u}} > 0\), then the right hand side integral is taken over a limit from a smaller value to a larger one, but if \(\frac{\dd{x}}{\dd{u}} < 0\), then the integral is the `wrong way round'.
If \(I = [a,b]\) and \(I' = x^{-1} I\), we have
\[
	\int_I f(x) \dd{x} = \int_{I'} f(x(u)) \abs{\frac{\dd{x}}{\dd{u}}} \dd{u}
\]
where the absolute value is used since \(I'\) is defined as going from the lower limit to the upper limit.
There is a similar formula in 2D.
\begin{proposition}
	Let \(\vb x(u, v) = (x(u, v), y(u, v))\) be a smooth, invertible transformation with a smooth inverse that maps the region \(D'\) in the \((u, v)\) plane to the region \(D\) in the \((x, y)\) plane.
	(This map must be a bijection; every point must have a unique inverse.) Then
	\[
		\iint_D f(x, y) \dd{x} \dd{y} = \iint_{D'} f(x(u, v), y(u, v)) \abs{\frac{\partial (x, y)}{\partial (u, v)}}\dd{u} \dd{v}
	\]
	where
	\[
		\frac{\partial (x, y)}{\partial (u, v)} = J = \det \begin{pmatrix}
			\partial x / \partial u & \partial x / \partial v \\
			\partial y / \partial u & \partial y / \partial v
		\end{pmatrix} = \det \left( \frac{\partial \vb x}{\partial u} \,\middle|\, \frac{\partial \vb x}{\partial v} \right)
	\]
	is the Jacobian determinant.
	More concisely,
	\[
		\dd{x} \dd{y} = \abs{J} \dd{u} \dd{v}
	\]
	It doesn't matter if the Jacobian vanishes at a single point, since the area of a single point is zero and hence will have no contribution to the result.
	The Jacobian being zero means that something non-smooth is happening at this point, so it is important to consider why this point is special.
\end{proposition}
\begin{proof}
	We can form a partition of \(D\) by using the image of a rectangular partition of \(D'\).
	Let the rectangular partition be characterised by a horizontal step \(\delta x\) and a vertical step of \(\delta y\).
	Then each small rectangle in \(D'\) is mapped to some small (not necessarily rectangular) region in \(D'\), with vertices
	\[
		\vb x(u_i, v_j), \vb x(u_{i+1}, v_j), \vb x(u_{i+1}, v_{j+1}), \vb x(u_i, v_{j+1})
	\]
	To first order, the area of this region is the area of the parallelogram with the same vertices.
	Two of the sides of the parallelogram are
	\[
		\vb x(u_{i+1}, v_j) - \vb x(u_i, v_j) \approx \frac{\partial \vb x}{\partial u}(u_i, v_j) \delta u
	\]
	\[
		\vb x(u_i, v_{j+1}) - \vb x(u_i, v_j) \approx \frac{\partial \vb x}{\partial v}(u_i, v_j) \delta v
	\]
	So the area of the parallelogram is approximately
	\begin{align*}
		\abs{\frac{\partial \vb x}{\partial u}(u_i, v_j) \delta u \cdot \frac{\partial \vb x}{\partial v}(u_i, v_j) \delta v} & = \abs{\det \left( \frac{\partial \vb x}{\partial u}(u_i, v_j) \,\middle|\, \frac{\partial \vb x}{\partial v}(u_i, v_j) \right)} \\
		                                                                                                                      & = \abs{J(u_i, v_j)} \,\delta u \,\delta v                                                                                        \\
		                                                                                                                      & = \delta A_{ij}
	\end{align*}
	Hence,
	\begin{align*}
		\int_D f \dd{A} & = \lim_{\varepsilon \to 0} \sum_{ij} f(x_i, y_j)\,\delta A_{ij}                                           \\
		                & = \lim_{\varepsilon \to 0} \sum_{ij} f(x(u_i, v_j), y(u_i, v_j)) \,\abs{J(u_i, v_j)} \,\delta u\,\delta v \\
		                & = \iint_{D'} f(x(u, v), y(u, v)) \,\abs{J(u_i, v_j)} \dd{u} \dd{v}
	\end{align*}
\end{proof}
As an example, let us consider polar coordinates \((\rho, \phi)\), where
\[
	x(\rho, \phi) = \rho \cos \phi;\quad y(\rho, \phi) = \rho \sin \phi
\]
Hence,
\[
	\abs{J} = \abs{\det \begin{pmatrix}
			\cos \phi & -\rho \sin \phi \\
			\sin \phi & \rho \cos \phi
		\end{pmatrix}} = \abs{\rho} = \rho
\]
If \(D = \{ (x, y) \colon x > 0,\, y > 0,\, x^2 + y^2 < r^2 \}\), which is a quarter-circle of radius \(r\) in the first quadrant, then \(D' = \{ (\rho, \phi) \colon 0 < \rho < r,\, 0 < \phi < \frac{\pi}{2} \}\).
This is notably a rectangle in polar coordinates.
\[
	\iint_D f(x, y)\dd{x} \dd{y} = \iint_{D'} f(\rho \cos \phi, \rho \sin \phi) \,\rho \dd{\rho} \dd{\phi}
\]
So, for example, if we let \(r \to \infty\), then
\[
	\int_{x=0}^\infty \int_{y=0}^\infty f(x, y) \dd{y}\dd{x} = \int_{\phi = 0}^{\frac{\pi}{2}} \int_{\rho = 0}^\infty f(\rho \cos \phi, \rho \sin \phi) \,\rho\dd{\rho}\dd{\phi}
\]
Consider
\[
	I = \int_0^\infty e^{-x^2} \dd{x}
\]
Then,
\begin{align*}
	I^2        & = \int_0^\infty e^{-x^2} \dd{x} \cdot \int_0^\infty e^{-y^2} \dd{y}                                  \\
	           & = \int_{x=0}^\infty \int_{y=0}^\infty e^{-x^2-y^2} \dd{y}\dd{x}                                      \\
	           & = \int_{\phi = 0}^{\frac{\pi}{2}} \int_{\rho = 0}^\infty e^{-\rho^2} \,\rho\dd{\rho}\dd{\phi}        \\
	           & = \frac{\pi}{2} \int_0^\infty \frac{\dd}{\dd{\rho}} \left( -\frac{1}{2}e^{-\rho^2} \right) \dd{\rho} \\
	           & = \frac{\pi}{4}                                                                                      \\
	\implies I & = \frac{\sqrt{\pi}}{2}
\end{align*}

\subsection{Definition of integral in three dimensions}
To integrate over regions \(V\) in \(\mathbb R^3\), we can use similar ideas to those discussed in the previous lecture.
\[
	\int_V f(\vb x) \dd{V} = \lim_{\varepsilon \to 0} \sum_{i,j,k} f(x_i, y_j, z_k) \,\delta V_{ijk}
\]
where the \(\delta V_{ijk}\) partition \(V\), and each contain the point \((x_i, y_j, z_k)\).
In this case, the volume element satisfies
\[
	\dd{V} = \dd{x}\dd{y}\dd{z}
\]
The integrals may be computed in any order.
As an example, consider the simplex defined by
\[
	V = \{ x > 0,\, y > 0,\, z > 0,\, x+y+z < 1 \}
\]
We can compute the volume using the integral
\begin{align*}
	I & = \int_{z=0}^1 \int_{y=0}^{1-z} \int_{x=0}^{1-y-z} 1 \dd{x}\dd{y}\dd{z}                                                        \\
	  & = \int_{z=0}^1 \int_{y=0}^{1-z} (1-y-z)\dd{y}\dd{z}                                                                            \\
	  & = \int_{z=0}^1 \left((1-z) - \frac{1}{2}(1-z)^2 - (1-z)z\right) \dd{z}                                                         \\
	  & = \left[ z - \frac{1}{2}z^2 - \frac{1}{2}z + \frac{1}{2}z^2 - \frac{1}{6}z^3 - \frac{1}{2}z^2 + \frac{1}{3}z^3 \right]_{z=0}^1 \\
	  & = \frac{1}{6}
\end{align*}
We can compute things like the centre of mass, assuming it has constant density \(\rho = 1\).
Then
\[
	\vb X = \frac{1}{m} \int_V \rho \vb x \dd{V} = \frac{1}{4}\begin{pmatrix}
		1 \\1\\1
	\end{pmatrix}
\]
\begin{proposition}
	Let \(x(u, v, w), y(u, v, w), z(u, v, w)\) be a continuously differentiable bijection with a continuously differentiable inverse, that maps the volume \(V'\) to \(V\).
	The integral
	\[
		\iiint_V f(x, y, z)\dd{x}\dd{y}\dd{z} = \iiint_{V'} f(x(u, v, w), y(u, v, w), z(u, v, w))\,\abs{J}\dd{u}\dd{v}\dd{w}
	\]
	where
	\[
		J = \det\left( \frac{\partial \vb x}{\partial u} \,\middle|\, \frac{\partial \vb x}{\partial v} \,\middle|\, \frac{\partial \vb x}{\partial w} \right)
	\]
	More concisely,
	\[
		\dd{x}\dd{y}\dd{z} = \abs{J}\dd{u}\dd{v}\dd{w}
	\]
\end{proposition}
The Jacobian comes from the fact that the volume of a parallepiped generated by the vectors
\[
	\frac{\partial \vb x}{\partial u} \delta u,\,\frac{\partial \vb x}{\partial v} \delta v,\,\frac{\partial \vb x}{\partial w} \delta w
\]
is precisely the determinant of the Jacobian matrix multiplied by \(\delta u\,\delta v\,\delta w\).
The rest of this proof follows from the two-dimensional case.
As an example, let us consider cylindrical polar coordinates \((u, v, w) = (\rho, \phi, z)\).
\[
	\dd{V} = \rho \dd{\rho} \dd{\phi} \dd{z};\quad \abs{J} = \rho
\]
In spherical polar coordinates \((u, v, w) = (r, \theta, \phi)\),
\[
	\dd{V} = r^2 \sin\theta \dd{r} \dd{\theta} \dd{\phi};\quad \abs{J} = r^2\sin\theta
\]

\subsection{Calculating volumes}
We can use the volume element to calculate, for example, the volume of a ball of radius \(R\).
To begin, let us use Cartesian coordinates.
\begin{align*}
	\int_V \dd{V} & = \int_{z=-R}^R \dd{z} \int_{y = -\sqrt{R^2 - z^2}}^{\sqrt{R^2 - z^2}} \dd{y} \int_{x = -\sqrt{R^2 - z^2 - y^2}}^{\sqrt{R^2 - z^2 - y^2}} \dd{x}                             \\
	              & = \int_{z=-R}^R \dd{z} \int_{y = -\sqrt{R^2 - z^2}}^{\sqrt{R^2 - z^2}} \dd{y} \left[ 2\sqrt{R^2 - z^2 - y^2} \right]                                                         \\
	              & = \int_{z=-R}^R \dd{z} \left[ y\sqrt{R^2 - z^2 - y^2} + (R^2 - z^2) \arctan \left( \frac{y}{\sqrt{R^2 - z^2 - y^2}} \right)_{y=-\sqrt{R^2 - z^2}}^{\sqrt{R^2 - z^2}} \right] \\
	              & = \int_{z=-R}^R \dd{z} \left[ \pi (R^2 - z^2) \right]                                                                                                                        \\
	              & = \frac{4}{3}\pi R^3
\end{align*}
We can alternatively use spherical polar coordinates.
\begin{align*}
	\int_V \dd{V} & = \int_{r=0}^R \dd{r} \int_{\theta=0}^\pi \dd{\theta} \int_{\phi=0}^{2\pi} \dd{\phi} \cdot r^2 \sin\theta     \\
	              & = \int_{r=0}^R r^2\dd{r} \int_{\theta=0}^\pi \sin\theta\dd{\theta} \int_{\phi=0}^{2\pi} \dd{\phi}             \\
	              & = \int_{r=0}^R r^2\dd{r} \cdot \int_{\theta=0}^\pi \sin\theta\dd{\theta} \cdot \int_{\phi=0}^{2\pi} \dd{\phi} \\
	              & = \frac{1}{3}R^3 \cdot 2 \cdot 2 \pi                                                                          \\
	              & = \frac{4}{3}\pi R^3
\end{align*}
This is clearly a much cleaner computation.
Now, consider the a ball of radius \(a\) with cylinder of radius \(b<a\) removed from the centre aligned with the \(z\) axis.
To calculate this volume, the symmetry of the problem suggests we might want to use cylindrical polar coordinates.
\[
	V = \{ (\rho, \phi, z) \colon 0 < \rho^2 + z^2 < a^2,\, b < \rho < a \}
\]
\begin{align*}
	\int_V \dd{V} & = \int_{\rho=b}^a \rho\dd{\rho} \int_{\phi=0}^{2\pi} \dd{\phi} \int_{z=-\sqrt{a^2 - \rho^2}}^{\sqrt{a^2 - \rho^2}} \dd{z} \\
	              & = 2 \pi \int_b^a 2\rho\sqrt{a^2 - \rho^2}\dd{\rho}                                                                        \\
	              & = \frac{4}{3}\pi (a^2 - b^2)^{\frac{3}{2}}
\end{align*}
